package com.ruoyi.lipin.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lipin.domain.vo.LpProductTagVo;
import com.ruoyi.lipin.domain.bo.LpProductTagBo;
import com.ruoyi.lipin.service.ILpProductTagService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品标签关联
 *
 * @author ruoyi
 * @date 2025-03-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lipin/productTag")
public class LpProductTagController extends BaseController {

    private final ILpProductTagService iLpProductTagService;

    /**
     * 查询商品标签关联列表
     */
    @SaCheckPermission("lipin:productTag:list")
    @GetMapping("/list")
    public TableDataInfo<LpProductTagVo> list(LpProductTagBo bo, PageQuery pageQuery) {
        return iLpProductTagService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商品标签关联列表
     */
    @SaCheckPermission("lipin:productTag:export")
    @Log(title = "商品标签关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LpProductTagBo bo, HttpServletResponse response) {
        List<LpProductTagVo> list = iLpProductTagService.queryList(bo);
        ExcelUtil.exportExcel(list, "商品标签关联", LpProductTagVo.class, response);
    }

    /**
     * 获取商品标签关联详细信息
     *
     * @param productTagId 主键
     */
    @SaCheckPermission("lipin:productTag:query")
    @GetMapping("/{productTagId}")
    public R<LpProductTagVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long productTagId) {
        return R.ok(iLpProductTagService.queryById(productTagId));
    }

    /**
     * 新增商品标签关联
     */
    @SaCheckPermission("lipin:productTag:add")
    @Log(title = "商品标签关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LpProductTagBo bo) {
        return toAjax(iLpProductTagService.insertByBo(bo));
    }

    /**
     * 修改商品标签关联
     */
    @SaCheckPermission("lipin:productTag:edit")
    @Log(title = "商品标签关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LpProductTagBo bo) {
        return toAjax(iLpProductTagService.updateByBo(bo));
    }

    /**
     * 删除商品标签关联
     *
     * @param productTagIds 主键串
     */
    @SaCheckPermission("lipin:productTag:remove")
    @Log(title = "商品标签关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productTagIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] productTagIds) {
        return toAjax(iLpProductTagService.deleteWithValidByIds(Arrays.asList(productTagIds), true));
    }
}
